package ClientCommands;

import java.io.IOException;

import org.json.simple.JSONObject;

import Annotations.IsClientCommand;
import Commands.ClientCommandBase;
import Commands.ExecuteMethod;
import Helpers.ApplicationLogger;
import ServiceLayer.ServiceFacade;

@IsClientCommand
public class AddFeedBack extends ClientCommandBase<Boolean>{
	
	String page;
	String from;
	String message;
	
	public String getPage()
	{
		return page;
	}
	public void setPage(String page)
	{
		this.page = page;
	}
	
	public String getFrom()
	{
		return from;
	}
	public void setFrom(String from)
	{
		this.from = from;
	}
	
	public String getMessage()
	{
		return message;
	}
	public void setMessage(String message)
	{
		this.message = message;
	}
	
	public AddFeedBack()
	{
		setCommandName("AddFeedBack");
		setCommandDescription("Add feedback command");
		setExecuteMethod(ExecuteMethod.ServerOnly);
	}
	
	@Override
	protected void ExecuteInternal() throws IOException {
		// TODO Auto-generated method stub
		Boolean status = false;
		try {
			ServiceLayer.ServiceFacade sf = new ServiceFacade();
			status = sf.AddFeedBack(getPage(), getFrom(), getMessage());
		} catch (Throwable e) {
			ApplicationLogger.getInstance().LOG.error(e.getMessage());
		}
		setResult(status);
	}
	
	@Override
	public void FillFromJSON(JSONObject jObj) {
		super.FillFromJSON(jObj);
		setPage((String)jObj.get("Page"));
		setFrom((String)jObj.get("From"));
		setMessage((String)jObj.get("Message"));
	}
	
	@Override
	public String toJSONString() {
			StringBuffer sb = new StringBuffer();
			sb.append("{");
			sb.append("\"" + JSONObject.escape("CommandName") + "\"");                 
			sb.append(":");                 
			sb.append("\"" + JSONObject.escape(getCommandName()) + "\"");                                  
			sb.append(",");                                  
			sb.append("\"" + JSONObject.escape("CommandDescription") + "\"");                 
			sb.append(":");                 
			sb.append("\"" + getCommandDescription() + "\"");   
			sb.append(",");  
			sb.append("\"" + JSONObject.escape("ExecuteMethod") + "\"");    
			sb.append(":");
			sb.append("\"" + getExecuteMethod() + "\"");   
			sb.append(",");
			sb.append("\"" + JSONObject.escape("Page") + "\"");
			sb.append(":");
			sb.append("\"" + JSONObject.escape(getPage()) + "\"");
			sb.append(",");
			sb.append("\"" + JSONObject.escape("From") + "\"");
			sb.append(":");
			sb.append("\"" + JSONObject.escape(getFrom()) + "\"");
			sb.append(",");
			sb.append("\"" + JSONObject.escape("Message") + "\"");
			sb.append(":");
			sb.append("\"" + JSONObject.escape(getMessage()) + "\"");
		sb.append("}");
		return sb.toString();
	}	
}
